package Java攻略._5_流式操作_lambda表达式与方法_引用的相关问题._2_lambda表达式与效果等同于final的变量;

import java.util.Arrays;
import java.util.List;

public class _6_对List中的所有值求和 {

    public static void main(String[] args) {

        List<Integer> integerList = Arrays.asList(1, 2, 3, 4, 5);

        int total = 0;
        for (int n : integerList){
            total += n;
        }
        System.out.println(total);

//        total = 0;
//        integerList.forEach(n -> total += n);

        total = 0;
        total = integerList.stream()
                .mapToInt(Integer::valueOf)
                .sum();
        System.out.println(total);
    }
}
